<!DOCTYPE html>
<html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
	    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	    <title>Hello APP</title>
	    <link rel="stylesheet" type="text/css" href="../../../css/index.css" />
	</head>
	<style type="text/css">
		.warp{width: 100%;}
		.mon::-webkit-input-placeholder{color: #BDBDBD;font-size: 16px;}
		.mon::-moz-placeholder{color: #BDBDBD;font-size: 16px;}

		.info-one{background: #FFFFFF;padding: 0 15px;margin-bottom: 10px;box-sizing: border-box;}
		.info-one .num-box{padding: 24px 0;box-sizing: border-box;}
		.info-one .num-box input{font-size: 16px;color: #333333;width: 100%;}
		.info-one .t{height: 30px;font-size: 12px;color: #3C94FF;line-height: 30px;}

		.title{height: 50px;padding: 0 15px;line-height: 50px;color: #333333;font-size: 15px;background: #FFFFFF;}
		.sel-pay{width: 100%;padding: 0 15px;box-sizing: border-box;background: #ffffff;}
		.sel-pay .sel-one{align-items:center;height: 50px;}
		.sel-pay .sel-one.on{background: url(../../../image/main2/pay_sel_on.png) no-repeat right center #FFFFFF;background-size:34px;}
		.sel-pay .sel-one img{width: 20px;height: 20px;}
		.sel-pay .sel-one .text{padding-left: 8px;box-sizing: border-box;font-size: 15px;}
		.sel-pay .sel-one .sta{font-size: 15px;color: #999999;background: url(../../../image/main1/down.png) no-repeat right center;background-size: 16px;
		text-align: right;padding-right: 20px;}
		.sel-pay .sel-one .r{text-align: right;font-size: 15px;color: #999999;padding-right:20px;box-sizing: border-box;
		background: url(../../../image/main3/main3_goto.png) no-repeat right center;background-size: 16px;}

		.bankcard-list{width: 100%;}
		.bankcard-list .bankcard-one{width: 100%;background: #F8F8F8;height: 40px;border-radius: 2px;line-height: 40px;padding-left:10px;box-sizing: border-box;
		font-size: 15px;color: #333333;margin-bottom: 12px;}
		.bankcard-list .bankcard-one.on{background: url(../../../image/main2/pay_sel_on.png) no-repeat right center #FFF9F0;background-size: 34px;border: 1px solid #FF9502;box-sizing: border-box;color: #FF9502;}

		.info-box{width: 100%;margin-bottom: 10px;}
		.info-box .info-input{align-items: center;padding:15px;background: #FFFFFF;box-sizing: border-box;}
		.info-box .info-input .text{font-size: 14px;}
		.info-box .info-input .cont{font-size: 14px;color: #666666;padding-left: 20px;text-align: right;}
		.info-box .info-input .cont.r{padding-right: 6px;box-sizing: border-box;}
	</style>
	<body>

		<div id="vue" class="warp">

			<!--提现金额-->
			<div class="info-one">
				<div class="num-box border-bottom">
					<input class="mon" type="number" id="money" placeholder="请输入提现金额(元)">
				</div>
				<div class="t">可提现金额：<i v-text="Pdata.money"></i>元</div>
			</div>

			<!--选择支付方式-->
			<div class="title">选择提现账户</div>
			<div class="sel-pay">

				<div class="sel-one flex" v-if="Pdata.bankcard && Pdata.bankcard.length == 0"  onclick="goBank()">
					<img src="../../../image/main2/pay_sel4.png"/>
					<div class="text">银行卡</div>
					<div class="flex1 r">去添加银行卡</div>
				</div>
				<div class="sel-one flex border-top" v-if="!Pdata.oauth || !Pdata.oauth.wxapp || !Pdata.oauth.wxapp.id"  onclick="bandwxin()">
					<img src="../../../image/main2/pay_sel2.png"/>
					<div class="text">微信支付</div>
					<div class="flex1 r">点击去绑定</div>
				</div>

				<div class="sel-one flex" v-if="Pdata.bankcard && Pdata.bankcard.length > 0" data-index='no' data-type="bankcard" onclick="tab_type(this);">
					<img src="../../../image/main2/pay_sel4.png"/>
					<div class="text">银行卡</div>
				</div>
				<div class="bankcard-list" v-if="Pdata.bankcard && Pdata.bankcard.length > 0">
					<div class="bankcard-one" :data-id="item.id" data-type="bankcard" :data-index="key" tapmode onclick="tabBank(this)" v-for="(item,key) in Pdata.bankcard" >
						<i v-text="item.bankName"></i>(<i v-text="item.cardNumberShow"></i>)
					</div>
				</div>
				<div class="sel-one flex border-top" v-if="Pdata.oauth && Pdata.oauth.wxapp && Pdata.oauth.wxapp.id" onclick="tab_type(this);" data-type="wxpay" v-if="Pdata.oauth && Pdata.oauth.wxapp">
					<img src="../../../image/main2/pay_sel2.png"/>
					<div class="text">微信支付</div>
				</div>
				<div class="sel-one flex border-top" onclick="tab_type(this);" data-type="alipay">
					<img src="../../../image/main2/pay_sel3.png"/>
					<div class="text">支付宝支付</div>
				</div>

			</div>

			<div class="info-box border-top" style="display:none;" id="zhifubao">
				<div class="info-input flex border-bottom">
	        		<div class="text">姓名</div>
					<input class="cont flex1 r" type="text" :value="Pdata.oauth && Pdata.oauth.alipay && Pdata.oauth.alipay.name ? Pdata.oauth.alipay.name : ''" maxlength="5" id="name" placeholder="请输入姓名">
	        	</div>
				<div class="info-input flex">
	        		<div class="text">支付宝账号</div>
					<input class="cont flex1 r" type="tel" :value="Pdata.oauth && Pdata.oauth.alipay && Pdata.oauth.alipay.account ? Pdata.oauth.alipay.account : ''" maxlength="11" id="account" placeholder="请输入支付宝账号">
	        	</div>
	        </div>

			<div style="width:100%;height:200px;"></div>
			<div class="warp-btn" id="app-footer">
	            <div class="btn" style="font-size: 15px;" tapmode onclick="tiXian()">确认提现</div>
	        </div>

		</div>
	</body>
</html>
<script type="text/javascript" src="../../../script/base.min.js" id="loadjs" data-js="L/swiper.min,L/lazyload,L/h-tool"></script>
<script type="text/javascript">
	define(function (require, exports, module) {

		var payData = {
			txinfo:{}
		};
		var stype = pageParam.type;
        var url = {
            "store":{
                "show":'store/Tixian/txpage',
				"pos":'store/Tixian/apply_tixian',
            },
            "company":{
                "show":'company/Tixian/txpage',
				"pos":'company/Tixian/apply_tixian',
            },
        }

		_page.getData = function(loading) {
            lanYun.getVueData({url:url[stype].show,get:{page:lanYun.page},cache:false,loading:loading},function(ret) {
                //console.log(JSON.stringify(ret));
            });
        };

		lanYun.newVue('#vue',{},function() {
			_page.getData(2);
	    });

		onShow = function () {
			lanYun.ajaxPageSta = 0; lanYun.page = 1;
			_page.getData(0);
		}

		//去提现
		tiXian = function (){
			var info = lanYun.vue.Pdata;
			payData.money = $('#money').val();

			if(!payData.money){
	            lanYun.toast('请输入提现金额');
	            return;
	        }
			if(!payData.money){
	            lanYun.toast('请输入提现金额');
	            return;
	        }
			if(!payData.payway){
	            lanYun.toast('请选择提现方式');
	            return;
	        }
			if(payData.payway == "wxpay" && payData.money < 1){
				lanYun.toast('微信提现金额最少为1元');
				return;
			}
			if(payData.payway == "bankcard"){
				if(!payData.txinfo.id){
					lanYun.toast('请先绑定银行卡');
		            return;
				}
			}
			if(payData.payway == "wxpay"){
				payData.txinfo = info.oauth.wxapp;
			}
			if(payData.payway == "alipay"){
				payData.txinfo = {};
				payData.txinfo.name = $('#name').val();
				payData.txinfo.account = $('#account').val();
				if(!payData.txinfo.name){
					lanYun.toast('请输入姓名');
		            return;
				}
				if(!payData.txinfo.account){
					lanYun.toast('请输入支付宝账号');
		            return;
				}
			}
			//console.log(JSON.stringify(payData));
			//return;
			lanYun.post( url[stype].pos , payData ,function (res) {
				//console.log(JSON.stringify(res));
				lanYun.toast(res.msg);
				if(res.errcode == 0){
					setTimeout(function () {
						api.closeWin();
					},500);
					// lanYun.openWin('main3/bank/tx_show.html', {
			        //     title :'提现结果',
			        //     frameParam : {id:res.data.id,type:stype}
			        // });
				}
	        },2);
		}

		//切换类型
		tab_type = function (tis) {
			var info = lanYun.vue.Pdata;
			var leng = $('.bankcard-list .bankcard-one').length;
	        var dst = tis.dataset;
			payData.txinfo = {};
			$('.sel-pay .sel-one').removeClass('on');
			if(leng > 0){
				$('.bankcard-list .bankcard-one').removeClass('on');
			}
			if(dst.type == 'bankcard' && leng > 0){
				$('.bankcard-list .bankcard-one').eq(0).addClass('on');
				payData.payway = dst.type;
				payData.txinfo = info.bankcard[0];
				return;
			}
			$(tis).addClass('on');
			payData.payway = dst.type;
			if(dst.type == 'alipay'){
				$('#zhifubao').show();
			}else {
				$('#zhifubao').hide();
			}
	    }

		//切换银行卡
		tabBank = function (tis) {
	        var dst = tis.dataset;
			var info = lanYun.vue.Pdata;
			$('#zhifubao').hide();
			$('.sel-pay .sel-one').removeClass('on');
			$(tis).addClass('on').siblings().removeClass('on');
			payData.payway = dst.type;
			payData.txinfo = info.bankcard[dst.index];
	    }

		//添加银行卡
		goBank = function (){
	        lanYun.openWin("main3/bank/bankcard.html", {
	            win:'win',
	           	title:'我的银行卡',
	            frameParam : {type:stype}
	        });
		}

		//绑定微信
		bandwxin = function (){
			var wxPlus = api.require('wxPlus');
			lanYun.showProgress({type:2});
			wxPlus.isInstalled(function(ret, err) {
				if (ret.installed){
					wxPlus.auth({},function(ret1, err1) {
						lanYun.hideProgress();
						if (ret1.status && ret1.code) {
							wxPlus.getToken({code:ret1.code}, function(ret2, err2) {
								if (ret2.status) {
									wxPlus.getUserInfo({accessToken:ret2.accessToken,openId:ret2.openId},function(ret3, err3) {
										if (ret3.status) {
											ret3.oauth = "wxapp";
											band_weixin(ret3);
										} else {
											lanYun.toast('登录失败');
										}
									});
								} else {
									lanYun.toast('登录失败');
								}
							});
						} else {
							switch(err1.code){
								case 1:
									lanYun.toast('登录授权失败');
								break;
								case 2:
									lanYun.toast('登录授权失败');
								break;
								case 3:
									lanYun.toast('当前设备未安装微信客户端');
								break;
							}
						}
					});
				} else {
					lanYun.toast('当前设备未安装微信客户端');
				}
				if(err){
					lanYun.hideProgress();
				}
			});
		}

		// 绑微信
		band_weixin = function(oauth){
			//console.log(JSON.stringify(oauth));
			lanYun.post('user/oauthband', oauth ,function (ret) {
				//console.log(JSON.stringify(ret));
				lanYun.toast(ret.msg);
				if(ret.errcode==0){
					lanYun.ajaxPageSta = 0; lanYun.page = 1;
					_page.getData(2);
				}
			},2);
		}

		//页面关闭方法
		backMenu = function (tis){
			api.closeWin();
		}

	});

</script>
